using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using BubzCommerce.CMS.Data.ManagerObjects;
using BubzCommerce.CMS.Data.BusinessObjects;
using BubzCommerce.CMS.Data.Base;

namespace BubzCommerce.CMS.Tests.Data
{
	[TestFixture]
    public partial class RedirectorpageLiveTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetRedirectorpageLiveManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected BubzCommerce.CMS.Data.ManagerObjects.IRedirectorpageLiveManager manager;

        protected BubzCommerce.CMS.Data.BusinessObjects.SitetreeLive CreateNewSitetreeLive()
        {
            BubzCommerce.CMS.Data.BusinessObjects.SitetreeLive entity = new BubzCommerce.CMS.Data.BusinessObjects.SitetreeLive();

            // You may need to maually enter this key if there is a constraint violation.
            //entity.Id = 1;

            entity.ClassName = "RedirectorPage";
            entity.Title = "Test Test ";
            entity.MenuTitle = "Test Test ";
            entity.SiteContent = "T";
            entity.MetaTitle = "Test Test ";
            entity.MetaDescription = "Tes";
            entity.MetaKeywords = "Test Test ";
            entity.ShowInMenus = true;
            entity.ShowInSearch = true;
            entity.Sort = 85;
            entity.Created = System.DateTime.Now;
            entity.Edited = System.DateTime.Now;

            using (BubzCommerce.CMS.Data.ManagerObjects.ISitetreeLiveManager sitetreeLiveMemberManager = managerFactory.GetSitetreeLiveManager())
                entity.SitetreeLiveMember = sitetreeLiveMemberManager.GetAll(1)[0];

            return entity;
        }

		protected BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive CreateNewRedirectorpageLive()
		{
			BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entity = new BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive();
			
			// You may need to maually enter this key if there is a constraint violation.
			//entity.Id = 64;
            
			entity.RedirectionType = "Test Test Test Tes";
			entity.Externalurl = "Test Test ";
			entity.LinkToid = 90;
			
			return entity;
		}
		protected BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive GetFirstRedirectorpageLive()
        {
            IList<BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
                BubzCommerce.CMS.Data.BusinessObjects.SitetreeLive sitetree = CreateNewSitetreeLive();
				BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entity = CreateNewRedirectorpageLive();

                entity.SitetreeLive = sitetree;
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                BubzCommerce.CMS.Data.BusinessObjects.SitetreeLive sitetree = CreateNewSitetreeLive();
                BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entityA = CreateNewRedirectorpageLive();

                entityA.SitetreeLive = sitetree;
                object result = manager.Save(entityA);

                BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                BubzCommerce.CMS.Data.BusinessObjects.SitetreeLive sitetree = CreateNewSitetreeLive();
                BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entity = CreateNewRedirectorpageLive();

                entity.SitetreeLive = sitetree;
                object result = manager.Save(entity);

                BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entityA = GetFirstRedirectorpageLive();
				
				entityA.RedirectionType = "Test Test Test Test Test Test Tes";
				
				manager.Update(entityA);

                BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.RedirectionType, entityB.RedirectionType);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                BubzCommerce.CMS.Data.BusinessObjects.SitetreeLive sitetree = CreateNewSitetreeLive();
                BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entity = CreateNewRedirectorpageLive();

                entity.SitetreeLive = sitetree;
                object result = manager.Save(entity);

                BubzCommerce.CMS.Data.BusinessObjects.RedirectorpageLive entityA = GetFirstRedirectorpageLive();

                manager.Delete(entityA);

                entityA = manager.GetById(entityA.Id);
                Assert.IsNull(entityA);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

